package cn.heycm.tenant.common.context;

import org.springframework.util.StringUtils;

/**
 * 多租户上下文，维护当前的租户信息
 *
 * @author hey
 * @version 1.0
 * @since 2024/8/24 22:55
 */
public class TenantContextHolder {

    private static final ThreadLocal<String> TENANT = new ThreadLocal<>();

    public static void set(String tenant) {
        TenantContextHolder.TENANT.set(tenant);
    }

    public static String get() {
        return TENANT.get();
    }

    public static void clear() {
        TENANT.remove();
    }

    public static boolean exist() {
        return StringUtils.hasText(TENANT.get());
    }
}
